Repository Public
1import { getAssetRow, readAsset } from "@/server/assets";23export const dynamic = "force-dynamic";4/**5 * Files readers may fetch: images of published sheets and the PDF of a current publication. Only assets flagged6 * public are served; everything else answers 404 whether it exists or not.7 */8export async function GET(req: Request, ctx: { params: Promise<{ id: string }> }) {9 const { id } = await ctx.params;10 const a = await getAssetRow(id);11 if (!a || !a.is_public) return new Response("Not found", { status: 404 });12 const data = await readAsset(a);13 const download = a.kind === "export" || new URL(req.url).searchParams.has("download");14 return new Response(new Uint8Array(data), { headers: {15 "Content-Type": a.mime, "Cache-Control": "public, max-age=86400", "X-Content-Type-Options": "nosniff",16 "Content-Security-Policy": "default-src 'none'; style-src 'unsafe-inline'; sandbox",17 "Content-Disposition": `${download ? "attachment" : "inline"}; filename="${a.filename.replace(/[^\w.@-]+/g, "_")}"`,18 } });19}20